package com.globaleducation365.cartoonv1.streaming;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;

public class Util {
	 /**
     * Convert time to a string
     * @param millis e.g.time/length from file
     * @return formated string (hh:)mm:ss
     */
    public static String millisToString(long millis) {
        boolean negative = millis < 0;
        millis = java.lang.Math.abs(millis);

        millis /= 1000;
        int sec = (int) (millis % 60);
        millis /= 60;
        int min = (int) (millis % 60);
        millis /= 60;
        int hours = (int) millis;

        String time;
        DecimalFormat format = (DecimalFormat)NumberFormat.getInstance(Locale.US);
        format.applyPattern("00");
        if (millis > 0) {
            time = (negative ? "-" : "") + hours + ":" + format.format(min) + ":" + format.format(sec);
        } else {
            time = (negative ? "-" : "") + min + ":" + format.format(sec);
        }
        return time;
    }
    
    public static String buildYoutubeUrl(String sUrl){
    	if (sUrl.toLowerCase().contains("www.youtube.com")) {
			if (sUrl.contains("&")) {
				String youtubeUrl = sUrl.split("&")[0];
				String id = youtubeUrl.split("=")[1];
				sUrl = "http://www.youtube.com/get_video_info?&video_id="
						+ id;
			} else {
				String id = sUrl.split("=")[1];
				sUrl = "http://www.youtube.com/get_video_info?&video_id="
						+ id;
			}
			// sUrl = getUrlVideoRTSP(sUrl);
			try {
				sUrl = MainActivity.calculateYouTubeUrl("37", true, sUrl);
			} catch (Exception e) {
				//tempUrl = getUrlVideoRTSP(sUrl);
				e.printStackTrace();
			}

		}
    	
    	return sUrl;
    }

}
